package com.egao.common.manage.student;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.cooperative.entity.CooperativeProjectActivityStudent;
import com.egao.common.module.cooperative.entity.vo.CooperativeProjectActivityStudentListVO;
import com.egao.common.module.cooperative.service.CooperativeProjectActivityStudentService;
import com.egao.common.module.student.entity.Student;
import com.egao.common.module.student.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 产教融合 学生端
 * @author root
 */
@Api(tags = "产教融合 学生端")
@RestController
@RequestMapping("${api}")
public class StudentCooperativeController extends BaseController {

    @Autowired
    private StudentService studentService;
    @Autowired
    private CooperativeProjectActivityStudentService cooperativeProjectActivityStudentService;

    @PreAuthorize("hasAuthority('student')")
    @ApiOperation(value = "产教融合学生报名活动列表")
    @ApiPageParam
    @GetMapping("/student/cooperative/page")
    public PageResult<CooperativeProjectActivityStudentListVO> activityPage(HttpServletRequest request) {
        Student student = studentService.getByUserId(getLoginUserId());
        if (student == null) {
            return new PageResult<>();
        }

        PageParam<CooperativeProjectActivityStudent> pageParam = new PageParam<>(request);
        pageParam.put("studentId", student.getId());
        return new PageResult<>(cooperativeProjectActivityStudentService.listActivityPage(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = "产教融合学生取消报名", desc = "产教融合学生取消报名", result = true)
    @ApiOperation(value = "产教融合学生取消报名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "CooperativeProjectActivityStudent", value = "CooperativeProjectActivityStudent", required = true, dataType = "CooperativeProjectActivityStudent")
    })
    @PutMapping("/student/cooperative/cancel")
    public JsonResult delete(@RequestBody CooperativeProjectActivityStudent cooperativeProjectActivityStudent) {
        return cooperativeProjectActivityStudentService.cancel(cooperativeProjectActivityStudent);
    }
}
